<?php

namespace app\cash\controller\goods;

use app\BaseController;

use app\cash\model\GoodsModel;
use app\stores\model\cash\CashCategoryModel;

class Goods extends BaseController{
    /**
     * 分类
     */
    public function categoryList(){
        $where['shop_id'] = $this->request->shopId;
        $where['type'] = 1;
        $where['status'] = 1;

        $order=['sort'=>'desc','category_id'=>'desc'];

        $return = CashCategoryModel::list($where,$order,$this->request->page,$this->request->limit);

        return $this->success($return);
    }
    /**
     * 菜品列表
     */
    public function index(){
        $search = $this->request->param('search');
        $cash_category_id = $this->request->param('cash_category_id/d',0);

        if($search) $where['search'] = $search;
        if($cash_category_id>0) $where['cash_category_id'] = $cash_category_id;
        $where['status'] = 1;
        $where['origin_type'] = 2;
        $where['shop_id'] = $this->request->shopId;
        //设置了售卖时间，还要查售卖时间内的

        $filed = 'g.start_sales_num,g.max_num,g.cover_img,g.quota,g.type,g.is_have_sku,g.cash_category_id,g.online_category_id,g.vip_discount_type,g.fictitious_take_count,g.goods_id,g.shop_id,g.name,g.cash_category_id,g.online_category_id,g.status,g.online_status,g.crossed_price,g.gross,g.support_service_type,
        g.origin_type,g.add_time,g.discount_detail,g.other_sku_id,sd.group_detail_name as unit_name';
        $return = GoodsModel::list($where,['add_time'=>'desc'],$this->request->page,$this->request->limit,$filed);
        return $this->success($return);
    }

}

